/**   
 * @Title: ServiceLocator.java 
 * @Package com.csis.framework.util 
 * @Description: TODO
 * @author dailey  
 * @date 2012-9-27
 * @version V1.0   
 */
package com.open.thinks.todo.system.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * @author dailey
 * 
 */
public class ServiceLocator implements BeanFactoryAware {

	private static BeanFactory beanFactory = null;

	private static ServiceLocator serviceLocator = null;

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		ServiceLocator.beanFactory = beanFactory;
	}

	public BeanFactory getBeanFactory() {
		return beanFactory;
	}

	public static ServiceLocator getInstance() {
		if (serviceLocator == null) {
			serviceLocator = (ServiceLocator) beanFactory
					.getBean("serviceLocator");
		}
		return serviceLocator;
	}

	public <T> T getService(String serviceName, Class<T> serviceClass) {
		return beanFactory.getBean(serviceName, serviceClass);
	}

	public <T> T getService(Class<T> serviceClass) {
		return beanFactory.getBean(serviceClass);
	}
}
